package org.hq.jni;

import org.hq.utils.HttpUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class VideoUtilsTest {
    @Autowired
    HttpUtils http;
    @Test
    void getDuration() {
        String m3u8_1="https://m3u8.44cdn.com/newhd/202404/6629385ce2519513f3e835e4/hls/index.m3u8";
        Imessage mess=new MyClass();
        int tns, thh, tmm, tss, tsss;
        tns = VideoUtils.getDuration(mess,m3u8_1);
        if(tns == -1)return;
        thh = tns / 3600;
        tmm = (tns % 3600) / 60;
        tss = (tns % 60);
        tsss = tns / 1000;
        System.err.println("总时长：" + thh + ":" + tmm + ":" + tss + ":" + tsss);
    }

    @Test
    void downloadVideo() {
        String m3u8_1="https://m3u8.44cdn.com/newhd/202404/6629385ce2519513f3e835e4/hls/index.m3u8";
        Imessage mess=new MyClass();
        VideoUtils.downloadVideo(mess,m3u8_1,"/tmp/javaout.mp4");
    }

    @Test
    void cutlVideo() {
        String mp4_119 = "https://d1.xia12345.com/video/202403/66026277ee252d1bd907921b/hd.mp4";
        String m3u8_119 = "https://svipsvip.ffzy-online5.com/20241102/34389_786929ce/index.m3u8";
        Imessage mess=new MyClass();
        int start = 5 * 60;
        VideoUtils.cutlVideo(mess,m3u8_119,"/tmp/java5-60.mp4",start, start + 5 * 60);
    }

    @Test
    void videoToJpg() {
        String mp4_119 = "https://d1.xia12345.com/video/202403/66026277ee252d1bd907921b/hd.mp4";
        String m3u8_119 = "https://svipsvip.ffzy-online5.com/20241102/34389_786929ce/index.m3u8";
        String out="/tmp/java5-60.jpg";
        String imageSize="320x320";
        Imessage mess=new MyClass();
        VideoUtils.VideoToJpg(mess,m3u8_119,out,imageSize);
    }

    @Test
    void videoToGit() {
        String mp4_119 = "https://d1.xia12345.com/video/202403/66026277ee252d1bd907921b/hd.mp4";
        String m3u8_119 = "https://svipsvip.ffzy-online5.com/20241102/34389_786929ce/index.m3u8";
        String outFile="/tmp/images/"+http.getTime()+".gif";
        String imageSize="320x320";
        Imessage mess=new MyClass();
       VideoUtils.VideoToGit(mess,m3u8_119,outFile,imageSize,5);
        System.out.println(http.getTime());
    }

    @Test
    void mkdir() {
        String folderPath = "/tmp/images"; // 替换为你想要检查的文件夹路径

        try {
            if (!Files.exists(Paths.get(folderPath))) {
                Files.createDirectories(Paths.get(folderPath));
                System.out.println("文件夹已创建: " + folderPath);
            } else {
                System.out.println("文件夹已存在: " + folderPath);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }














    }










}